package com.sxpcwlkj.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sxpcwlkj.common.code.controller.BaseController;
import com.sxpcwlkj.common.utils.AjaxResult;
import com.sxpcwlkj.framework.entity.page.PageQuery;
import com.sxpcwlkj.framework.entity.page.TableDataInfo;
import com.sxpcwlkj.system.entity.AdminMenuTree;
import com.sxpcwlkj.system.entity.bo.SysFunctionBo;
import com.sxpcwlkj.system.entity.vo.SysFunctionVo;
import com.sxpcwlkj.system.service.SysFunctionService;
import com.sxpcwlkj.system.service.SysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 系统资源
 * @Author sxpcwlkj
 * @Version v1.0.0
 */
@RequestMapping("system/function")
@RestController
@RequiredArgsConstructor
public class SysFunctionController extends BaseController {

    private final SysFunctionService baseService;
    private final SysUserService sysUserService;

    /**
     * 获取用户列表
     *
     * @return vo
     */
    @SaCheckPermission("system:user:list")
    @PostMapping("/list")
    public AjaxResult<List<SysFunctionVo>> listPage(SysFunctionBo bo, PageQuery pageQuery) {
        return AjaxResult.success(baseService.selectPageList(bo, pageQuery));
    }

    /**
     * 所有菜单
     * @return
     */
    @SaCheckPermission("system:user:list")
    @PostMapping("/menuList")
    public AjaxResult<List<AdminMenuTree>> menuList(){
        List<AdminMenuTree> functionTree = baseService.getAllMenuTree();
        return success(functionTree);
    }

    /**
     * 获取用户详细信息
     *
     * @return vo
     */
    @SaCheckPermission("system:user:query")
    @GetMapping("/{id}")
    public AjaxResult<SysFunctionVo> queryById(@PathVariable String id) {
        return success(baseService.selectVoById(id));
    }

    /**
     * 获取用户详细信息
     *
     * @return vo
     */
    @SaCheckPermission("system:user:edit")
    @PutMapping
    public AjaxResult<Boolean> edit(@Validated @RequestBody(required = false) SysFunctionBo bo) {
        return success(baseService.updateById(bo));
    }

    /**
     * 新增用户
     *
     * @return vo
     */
    @SaCheckPermission("system:user:insert")
    @PostMapping
    public AjaxResult<Boolean> insert(@Validated @RequestBody(required = false) SysFunctionBo bo) {
        return success(baseService.insert(bo));
    }

    /**
     * 删除用户
     *
     * @return vo
     */
    @SaCheckPermission("system:user:delete")
    @DeleteMapping("/{id}")
    public AjaxResult<Boolean> delete(@PathVariable String id) {
        return success(baseService.deleteById(id));
    }


}
